@extends('backstage.layout.master')
@section('title', '创作蒙板列表')
@section('content')
    <div class="breadcrumbs" id="breadcrumbs">
        <script type="text/javascript">
            try {
                ace.settings.check('breadcrumbs', 'fixed')
            } catch (e) {
            }
        </script>

        <ul class="breadcrumb">
            <li>
                <i class="icon-home home-icon"></i>
                <a target="_blank" href="backstage/home">主页</a>
            </li>

            <li class="active">
                <a target="_blank" href="/backstage/prod-temp-creation-mask/creation-mask-list">创作类型蒙板</a>
            </li>
            <li>
                创作类型蒙板列表
            </li>
        </ul><!-- .breadcrumb -->
        <div class="nav-search" id="nav-search">
        </div><!-- #nav-search -->
    </div>

    <div class="page-content">
        <div class="page-header">
            <h1>
                创作类型蒙板
                <small>
                    <i class="icon-double-angle-right"></i>
                    创作类型蒙板列表
                </small>
            </h1>
        </div>
        <div class="row">
            <div class="col-xs-12">
                <!-- PAGE CONTENT BEGINS -->
                <div class="table-responsive">
                    <table id="sample-table-1" class="table table-striped table-bordered table-hover">
                        <thead>
                        <tr>
                            <th class="center">
                                <label>
                                    <input type="checkbox" class="ace">
                                    <span class="lbl"></span>
                                </label>
                            </th>
                            <th>编号</th>
                            <th>名称</th>
                            <th>蒙板显示Ico</th>
                            <th>跳转类型</th>
                            <th>跳转参数</th>
                            <th>排序</th>
                            <th>操作</th>
                        </tr>
                        </thead>

                        <tbody>
                        @foreach ($creation_masks as $creation_mask)
                        <tr class="" data-tr-id="{{isset($creation_mask->id)?$creation_mask->id:0}}">
                            <td class="center">
                                <label>
                                    <input type="checkbox" class="ace">
                                    <span class="lbl"></span>
                                </label>
                            </td>
                            <td>{{isset($creation_mask->id)?$creation_mask->id:''}}</td>
                            <td>
                                {{isset($creation_mask->name)?$creation_mask->name:''}}
                            </td>
                            <td><img src="{{$creation_mask->original_image}}" width="30" height="30"></td>

                            <td class="hidden-480">
                                产品模板
                            </td>
                            <td>{{isset($creation_mask->product_temp_id)?$creation_mask->product_temp_id:''}}</td>
                            <td style="width:68px;">
                                <input type="number" min=1 step=1 name="sort" value="{{$creation_mask->sort}}" class="sort" style="width:50px;">
                                <input type="hidden" value="{{$creation_mask->sort}}">
                                <input type="hidden" value="{{$creation_mask->id}}">
                            </td>
                            <td>
                                <ul class="nav-pills" style="list-style-type:none">
                                    <li class="dropdown all-camera-dropdown">
                                        <a style = "color: #2709ff" target="_blank" href="/backstage/prod-temp-creation-mask/update-creation-mask?id={{isset($creation_mask->id)?$creation_mask->id:''}}">
                                            <span id="" style="font-weight: bold">编辑</span>
                                        </a>
                                    </li>
                                    <li data-filter-camera-type="all">
                                        <a  data-delete="{{isset($creation_mask->id)?$creation_mask->id:0}}" style = "cursor:pointer;color: red;margin-left: 15px">
                                            <span style="font-weight: bold">删除</span>
                                        </a>
                                    </li>
                                </ul>
                            </td>
                        </tr>
                        @endforeach
                        </tbody>
                    </table>
                </div>
                <div class="row">
                    <div class="col-sm-6">
                        <div class="dataTables_info" id="sample-table-2_info"></div>
                    </div>
                    <div class="col-sm-6">
                        <div class="dataTables_paginate paging_bootstrap">
                            <?php echo $creation_masks->render(); ?>
                        </div>
                    </div>
                </div>
                <!-- PAGE CONTENT ENDS -->
            </div><!-- /.col -->
        </div><!-- /.row -->
    </div><!-- /.page-content -->
@stop
@section('script')
    <script type="text/javascript">
        $(function () {
            $('[data-rel=tooltip]').tooltip();
            $('[data-delete]').click(function(){
                var  id = $(this).attr("data-delete");
                console.log('id:'+id);
                bootbox.setLocale("zh_CN");
                bootbox.confirm({
                    size: 'small',
                    message: "你确定要删除吗？",
                    callback: function(result){
                        if(result)
                        {
                            $.post("/backstage/prod-temp-creation-mask/delete-creation-mask",
                                    {
                                        id:id,
                                        _token:"{{csrf_token()}}"
                                    },
                                    function(data){
                                        if(data.state==1)
                                        {
                                            $('[data-tr-id='+id+']').remove();
                                            showMessage('','删除成功');
                                        }else {
                                            showMessage('',data.message);
                                        }
                                    });
                        }
                    }
                });

            });
            $('table th input:checkbox').on('click' , function(){
                var that = this;
                $(this).closest('table').find('tr > td:first-child input:checkbox')
                        .each(function(){
                            this.checked = that.checked;
                            $(this).closest('tr').toggleClass('selected');
                        });

            });
            $(".sort").blur(function(){
                var sort = $(this).next().val();
                var newSort = $(this).val();
                var id = $(this).next().next().val();
                var a = $(this);
                if(newSort == sort){
                    return;
                }else{
                    $.ajax({
                        type: "POST",
                        url: "backstage/prod-temp-creation-mask/update-sort",
                        data:{"sort":newSort,"id":id},
                        success: function(msg){
                            if(msg.state==1){
                                swal({
                                    title: "更新成功！",
                                    text: "",
                                    type: "success",
                                    timer:2000
                                });
                                window.location.reload()
                            }else {
                                swal({
                                    title: msg.message,
                                    text: "",
                                    type: "error",
                                    timer:2000
                                });
                            }
                        },
                        error:function(){
                            swal({
                                title: "系统繁忙稍后再试",
                                text: "",
                                type: "error",
                                timer:2000
                            });
                        }
                    });
                }
            });
        });
    </script>
@stop